package com.hjs.servlet.regularinspection.pavementflatness;

import com.hjs.bean.PavementFlatness;
import com.hjs.mapper.RegularInspectionMapper;
import com.hjs.tools.Mapper;
import com.hjs.tools.RequestUtil;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/PavementFlatness/update")
public class UpdatePavementFlatness extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) {
        /*
         * 提供参数
         * userID
         * IRI
         * regularInspectionID
         * flatnessDate
         * remarks （可选）
         */
        RequestUtil requestUtil = new RequestUtil(request,response);
        Mapper<RegularInspectionMapper> regularInspectionMapperMapper = new Mapper<>(RegularInspectionMapper.class);
        PavementFlatness pavementFlatness = new PavementFlatness(requestUtil.getInt("flatnessID"),
                requestUtil.getDateTime("flatnessDate"),requestUtil.getString("userID"),
                requestUtil.getDouble("IRI"),requestUtil.getString("remarks"),
                requestUtil.getInt("regularInspectionID"));
        try {
            RegularInspectionMapper regularInspectionMapper = regularInspectionMapperMapper.getMapper();
            boolean result = regularInspectionMapper.updateOnePavementFlatness(pavementFlatness);
            requestUtil.responseWrite("{\"result\":" + result + "}");
        } catch (Exception e) {
            requestUtil.responseWrite("{\"result\": false}");
        } finally {
            regularInspectionMapperMapper.closeSession();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
        doPost(request,response);
    }
}
